package entity;

import java.io.FileWriter;

public class SalaryTest {
    public static void main(String[] args) {
        // 测试数据
        Employee zhang = new HourlyEmployee("张三", "E001", 50, 160);
        Employee li = new Manager("李四", "M001", 15000, 5000);

        // 处理薪资和存储
        process(zhang);
        process(li);
    }

    private static void process(Employee emp) {
        try {
            double salary = emp.calculateSalary();
            String paySlip = emp.generatePaySlip(salary);
            System.out.println(emp.getName() + "工资条：\n" + paySlip + "\n");

            // 存储到文件
            FileWriter writer = new FileWriter("工资条_" + emp.getEmpId() + ".txt");
            writer.write(paySlip);
            writer.close();
            System.out.println("文件已保存：工资条_" + emp.getEmpId() + ".txt\n");
        } catch (Exception e) {
            System.out.println(emp.getName() + "计算失败：" + e.getMessage() + "\n");
        }
    }
}